package day04;
//猜数字游戏
import java.util.Scanner;
public class Guessing {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        //列1：while 雏形
/*
        int num =300;//手里藏得数字
        System.out.println("猜数字");
        int guess =sc.nextInt();//1

        while (num!=guess){//2
            System.out.println("猜吧");
            guess = sc.nextInt();//3
        }
        System.out.println("恭喜你猜对了");

 */

        /*   解析1：
           int num = 300;手里藏得数字
while :要素1.对你输入的数字进行扫描，
          2.你输入的数字和藏得数字进行比较，相同输出，
          3.不相同重新扫描你输入的数字，反复循环

 */




//列2：while 固定值；进阶
/*

        //400（大），200（小） 300（对）
        int num =300;
        System.out.println("猜吧");
        int guess  = sc.nextInt();//1
        while (guess!=num){//2
            if (guess>num){
                System.out.println("猜大了");
            }else {
                System.out.println("猜小了");
            }
            System.out.println("猜吧");
            guess =sc.nextInt();//3
        }
        System.out.println("恭喜你猜对了");

 */

/*
    解析2：
int num =250;
猜吧！
300
猜大了！



 */

//列2.2    while  固定值：
/*
        int num =300;
        System.out.println("猜吧");
        int guess  = sc.nextInt();//1
        while (true){//2
            if (guess>num){
                System.out.println("猜大了");
            }else if(guess <num) {
                System.out.println("猜小了");
            }else {
                System.out.println("恭喜你猜对了");
                break;
            }
            System.out.println("猜吧");
            guess =sc.nextInt();//3
        }

 */

//Guessing随机猜数字 while版：方法：
        /*
        int num =(int) (Math.random()*100+1);
        System.out.println(num);
        System.out.println("猜一个数字");
        int guess =sc.nextInt();
        while (true){
            if (guess>num){
                System.out.println("猜大了");
            }else if (guess<num){
                System.out.println("猜小了");
            }else {
                System.out.println("猜对了");
                break;
            }
            System.out.println("再接再厉");
            guess = sc.nextInt();

        }

         */



        //列3：生成随机数：Math.random();是生成随机数：
/*
        System.out.println(Math.random());//0~0.9999999...的随机数
        int num =(int)(Math.random()*1000+1);//1到1000之内的随机数字
        System.out.println(num);

 */



//雏形： 随机 do..while
/*
        int num =(int)(Math.random()*1000+1);//1到1000之内的随机数字
        System.out.println(num);

        int guess;
        do {
            System.out.println("猜吧");
            guess = sc.nextInt();//相当于要素1和3
        }while (guess!=num);//2

 */





//进阶：  随机  do ......while
   /*
//       假设num=250
        //300（大）200（小）250（对）
        int num =(int)(Math.random()*1000+1);//1到1000之内的随机数字
        System.out.println(num);

        int guess;
        do {
            System.out.println("猜吧");
            guess = sc.nextInt();//相当于循环要素1和3
            if (guess>num){
                System.out.println("猜大了");
            } else if (guess<num) {
                System.out.println("猜小了");
            }else {
                System.out.println("猜对了");
            }
        }while (guess!=num);//2

 */








    }
}




